package com.wlcorp.forcazamis.business.baseinfo.impl;

import java.util.List;

import com.wlcorp.forcazamis.business.baseinfo.IFactoryService;
import com.wlcorp.forcazamis.dao.baseinfo.IFactoryDAO;
import com.wlcorp.forcazamis.domain.baseinfo.Factory;
import com.wlcorp.forcazamis.exception.ServiceException;
import com.wlcorp.forcazamis.sys.BaseService;
import com.wlcorp.forcazamis.sys.util.AppConstant;

public class FactoryServiceImpl extends BaseService implements
		IFactoryService {
	
	private IFactoryDAO factoryDAO;
	public List<Factory> getFactoryList(Factory factory)
			throws ServiceException {
		return factoryDAO.getFactoryList(factory);
	}

	public Factory getFactoryById(Long factoryId)
			throws ServiceException {
		if(null == factoryId){
			return null;
		}
		return factoryDAO.getFactoryById(factoryId);
	}

	public void saveFactory(Factory factory) throws ServiceException {
		if(null == factory.getFactoryId()){
			List<?> factoryList = factoryDAO.getFactoryList(factory);
			if(factoryList.size() > 0){
				setErrorField(factory,AppConstant.BASE_BEAN_STATUS_ERROR,"打样工厂编号不能重复！");
				return;
			}
		}
		factoryDAO.saveFactory(factory);
	}

	public void setFactoryDAO(IFactoryDAO factoryDAO) {
		this.factoryDAO = factoryDAO;
	}

	public void deleteFactory(Factory factory) throws ServiceException {
		factoryDAO.deleteFactory(factory);
	}
	
}
